// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   CMLogger.java

package com.boci.common.util;

import java.io.*;
import java.util.logging.*;

// Referenced classes of package com.boci.common.util:
//            AppConfigurator

public class CMLogger
{

    public CMLogger()
    {
    }

    private static void init()
    {
        InputStream is;
        boolean enableFlag;
        int intLimit;
        int intCount;
        boolean appendFlag;
        Level level;
        is = null;
        String strLimit = null;
        String strCount = null;
        String strLevel = null;
        String strPattern = null;
        enableFlag = !"Y".equalsIgnoreCase("N");
        intLimit = 0xf4240;
        intCount = 3;
        appendFlag = true;
        level = "SEVERE".equalsIgnoreCase("INFO") ? Level.INFO : Level.SEVERE;
        try{
	        LogManager.getLogManager().reset();
	        appConfigurator = AppConfigurator.getInstance();
	        strPattern = appConfigurator.getAppConfig("LOG_FILE");
	        strLevel = appConfigurator.getAppConfig("LOG_LEVEL");
	        strLimit = appConfigurator.getAppConfig("LOG_LIMIT");
	        strCount = appConfigurator.getAppConfig("LOG_COUNT");
	        enableFlag = appConfigurator.getBoolean("LOG_ENABLE");
	        if(enableFlag)
	        {
	            if(strLevel != null && (strLevel.equalsIgnoreCase("INFO") || strLevel.equalsIgnoreCase("SEVERE")))
	                level = strLevel.equalsIgnoreCase("INFO") ? Level.INFO : Level.SEVERE;
	            try
	            {
	                intLimit = Integer.parseInt(strLimit);
	            }
	            catch(Exception e)
	            {
	                intLimit = 0xf4240;
	            }
	            try
	            {
	                intCount = Integer.parseInt(strCount);
	            }
	            catch(Exception e)
	            {
	                intCount = 3;
	            }
	            if(strPattern == null)
	                throw new Exception("Parameter LOG_File is not set");
	            File logFile = new File(strPattern);
	            File logDir = new File(logFile.getParent());
	            if(!logDir.exists())
	                logDir.mkdirs();
	        }
	        Handler handler = new FileHandler(strPattern, intLimit, intCount, appendFlag);
	        handler.setFormatter(new SimpleFormatter());
	        handler.setLevel(enableFlag ? level : Level.OFF);
	        mLogger = Logger.getLogger(com.boci.common.util.CMLogger.class.toString());
	        mLogger.addHandler(handler);
    	}catch(Exception ex){
            System.out.println("Initialize Logger failed! ...");
            ex.printStackTrace();
            Handler handler = new ConsoleHandler();
            handler.setLevel(enableFlag ? level : Level.OFF);
            mLogger = Logger.getLogger(com.boci.common.util.CMLogger.class.toString());
            mLogger.addHandler(handler);    		
    	}finally{
	        if(is != null)
	            try
	            {
	                is.close();
	            }
	            catch(Exception e)
	            {
	                e.printStackTrace();
	            }
    	}
    	return;
    }

    public static Logger getInstance()
    {
        if(mLogger == null)
            init();
        return mLogger;
    }

    protected static Logger mLogger = null;
    private static AppConfigurator appConfigurator = null;

}
